﻿using CommunityToolkit.Mvvm.DependencyInjection;
using CSharpDevTools.Core;
using CSharpDevTools.ViewModels;
using HandyControl.Data;
using HandyControl.Properties.Langs;
using HandyControl.Tools;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;

namespace CSharpDevTools
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        private static Mutex AppMutex;

        protected override void OnStartup(StartupEventArgs e)
        {
            AppMutex = new Mutex(true, "CSharpDevTools", out var createdNew);

            if (!createdNew)
            {
                var current = Process.GetCurrentProcess();

                foreach (var process in Process.GetProcessesByName(current.ProcessName))
                {
                    if (process.Id != current.Id)
                    {
                        process.Kill();
                        break;
                    }
                }
            }

            ShutdownMode = ShutdownMode.OnMainWindowClose;
            Ioc.Default.ConfigureServices(
               new ServiceCollection()
               .AddTransient<MainWindowViewModel>()
               .AddTransient<HomeControlViewModel>()
               .AddTransient<MD5ControlViewModel>()
               .AddTransient<DESControlViewModel>()
               .AddTransient<DES_JSControlViewModel>()
               .AddTransient<Base64ControlViewModel>()
               .AddTransient<ImageBase64ControlViewModel>()
               .AddTransient<TimestampControlViewModel>()
               .AddTransient<JsonControlViewModel>()
               .BuildServiceProvider());
            base.OnStartup(e);
        }
    }
}
